import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/**
 * TransActie overzicht GUI
 * @author Jeroen
 *
 */
public class OverzichtGUI extends JFrame implements ActionListener{

	private static final long serialVersionUID = 1L;
	private JButton b;
	private JTextArea ta;
	private JComboBox cb;
	private Bank bank;
	private Rekening rekening;
	private int pWidth = 800, pHeight = 400;
	
	/**
	 * Constructor voor de medewerker
	 * @param b
	 */
	public OverzichtGUI(Bank b){
		bank = b;
		
		Container c = getContentPane();
		c.setLayout(new BorderLayout());
		
		cb = new JComboBox(b.alleRekeningen());
		ta = new JTextArea();
		this.b = new JButton("Terug");
		
		c.add(cb, BorderLayout.NORTH);
		JScrollPane scrollPane = new JScrollPane(ta);
	    
	    c.add(scrollPane, BorderLayout.CENTER);
		c.add(this.b, BorderLayout.SOUTH);
		
		cb.addActionListener(this);
		this.b.addActionListener(this);
		
		setSize(pWidth, pHeight);
		setTitle("Transactieoverzicht");
	    setVisible(true);
	    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	}
	/**
	 * Constructor voor de klant
	 * @param r
	 */
	public OverzichtGUI(Rekening r){
		rekening = r;
		
		Container c = getContentPane();
		c.setLayout(new BorderLayout());
	    ta = new JTextArea();
	    
	    drawOverzicht();
	    
	    JScrollPane scrollPane = new JScrollPane(ta);
	    
	    c.add(scrollPane, BorderLayout.CENTER);
	    b = new JButton("Terug");
	    c.add(b, BorderLayout.SOUTH);
	    
	    b.addActionListener(this);
	    
	    setSize(pWidth, pHeight);
	    setTitle("Transactieoverzicht");
	    setVisible(true);
	    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	}
	public void drawOverzicht(){
		ArrayList logLines = rekening.getLog();
	    
		ta.append("Klantnaam: " + rekening.getRekeningHouder().getNaam() + "\n" +
	    "Rekeningnummer: " + rekening.getRekNr() + "\n" +
	    "Saldo: " + rekening.getSaldo() + "\n");
	    
		for (int i = 0; i < logLines.size(); i++){
	    	String logLine = logLines.get(i).toString() + "\n";
	    	ta.append(logLine);
	    }
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == cb){
			ta.setText("");
			rekening = (Rekening) bank.alleRekeningen().get(cb.getSelectedIndex());
			drawOverzicht();
		}else{
			dispose();
		}
	}
}
